<template>
    <div class="home-page">
        <!-- 这里开始写新的首页内容 -->
         <div class="home-carousel">
            <div class="home-carousel-item">
                <HomeCarousel />
            </div>
            <div class="left-content">
                <div class="news-item notice">
                    <div class="news-header">
                        <span class="news-tag notice">最新公告</span>
                        <span class="news-date">2024-03-21</span>
                    </div>
                    <div class="news-content">
                        <h3>全新数据中心上线公告 </h3>
                        <p>为提供更优质的服务，我们新增了多个数据中心节点，覆盖更多地区...</p>
                    </div>
                </div>
                <div class="news-item tutorial">
                    <div class="news-header">
                        <span class="news-tag tutorial">最新教程</span>
                        <span class="news-date">2024-03-20</span>
                    </div>
                    <div class="news-content">
                        <h3>代理服务使用教程</h3>
                        <p>详细图文教程，帮助您快速上手使用我们的代理服务...</p>
                    </div>
                </div>
            </div>
         </div>
       <div class="home-content">
           <div class="content-main">
               <div class="news-list">
                   <div class="section-header">
                       <h2 class="section-title">最新资讯</h2>
                       <a href="/news" class="more-link">查看更多</a>
                   </div>
                   <div class="news-grid">
                       <div class="news-card" v-for="i in 10" :key="i">
                           <div class="news-card-image">
                               <img src="https://www.ipdodo.com/news/wp-content/themes/Relive-Pro/timthumb.php?src=https://www.ipdodo.com/news/wp-content/uploads/2024/11/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20241128185158-1024x458.jpg&w=800&h=600&zc=1&q=100" alt="新闻图片">
                               <span class="news-card-tag">资讯</span>
                           </div>
                           <div class="news-card-content">
                               <h3 class="title">HTTP代理服务器的工作原理及应用场景</h3>
                               <p class="news-card-desc">深入了解HTTP代理服务器的工作机制，以及在不同场景下的应用方案...</p>
                               <div class="news-card-meta">
                                   <span class="news-card-date">2024-03-21</span>
                                   <span class="news-card-views">
                                       <i class="view-icon">👁</i> 2,356
                                   </span>
                               </div>
                           </div>
                       </div>
                   </div>
               </div>
               <div class="content-sidebar">
                   <div class="ad-container">
                       <h3 class="ad-title">推荐产品</h3>
                       <div class="ad-content">
                           <div class="ad-banner">
                               <img src="../assets/images/guanggao.jpg" alt="广告图片">
                               <div class="ad-overlay">
                                   <h4>动态住宅IP</h4>
                                   <p>高质量动态住宅IP，支持全球地区...</p>
                               </div>
                           </div>
                       </div>
                   </div>
               </div>
           </div>
       </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            newsList: []
        }
    },
    async mounted() {
        try {
            const response = await fetch('/api/news/list')
            const { data } = await response.json()
            this.newsList = data.list
        } catch (error) {
            console.error('Failed to fetch news:', error)
        }
    }
}
</script>

<style scoped>
.home-page {
    padding: 24px;
    width: clamp(1200px, 85%, 1800px);
    margin: 0 auto;
}

.home-carousel {
    height: 500px;
    display: flex;
    gap: 24px;
}
.home-carousel-item{
    width:1100px;
    height: 500px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.left-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.news-item {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.news-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: linear-gradient(to right, #ffffff, #f8f9fa);
}

.news-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    transition: all 0.3s ease;
}

.news-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.news-tag {
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    color: white;
    font-weight: 500;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.news-tag.notice {
    background: linear-gradient(135deg, #1976d2, #2196f3);
}

.news-tag.tutorial {
    background: linear-gradient(135deg, #2e7d32, #4caf50);
}

.news-date {
    font-size: 12px;
    color: #666;
    background: #f5f5f5;
    padding: 4px 10px;
    border-radius: 5px;
}

.news-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.news-content h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: #333;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-content p {
    margin: 0;
    font-size: 14px;
    color: #666;
    line-height: 1.8;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    opacity: 0.85;
}

.home-content {
    margin-top: 40px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    /* border: 1px solid red; */
}

.section-title {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.more-link {
    color: #1976d2;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.3s;
}

.more-link:hover {
    color: #1565c0;
}

.news-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.news-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;
}

.news-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.news-card-image {
    position: relative;
    height: 200px;
    overflow: hidden;
}

.news-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.news-card:hover .news-card-image img {
    transform: scale(1.05);
}

.news-card-tag {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 4px 12px;
    background: #1976d2;
    color: white;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.news-card-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 120px;
}

.news-card-content .title {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: #333;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 22px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.news-card-desc {
    margin: 0;
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 44px;
    white-space: normal;
}

.news-card-meta {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #666;
}

.news-card-views {
    display: flex;
    align-items: center;
    gap: 4px;
}

.view-icon {
    font-style: normal;
}

.content-main {
    display: flex;
    justify-content: space-between;
    gap: 24px;
}

.news-list {
    border: none;
    width: 1300px;
    flex-shrink: 0;
}

.content-sidebar {
    position: sticky;
    top: 100px;
    flex: 1;
    min-width: 300px;
    max-width: 400px;
}

.ad-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    height: fit-content;
}

.ad-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    padding: 16px 20px;
    margin: 0;
    border-bottom: 1px solid #eee;
}

.ad-content {
    padding: 0;
}

.ad-banner {
    position: relative;
    width: 100%;
    height: 300px;
    overflow: hidden;
    cursor: pointer;
}

.ad-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.ad-banner:hover img {
    transform: scale(1.05);
}

.ad-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: white;
}

.ad-overlay h4 {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 600;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.ad-overlay p {
    margin: 0;
    font-size: 15px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.6;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
</style> 